/**
 *
 * Created by cy on 2017/6/14.
 *
 */
'use strict';

var gulp            = require('gulp'),
    browserSync     = require('browser-sync').create(),             //  
    reload          = browserSync.reload ,
    sass            = require('gulp-sass'),
    minify          = require('gulp-minify-css'),
    concat          = require("gulp-concat"),
    rename          = require("gulp-rename"),
    uglify          = require('gulp-uglify'),                       //  js文件压缩
    plumber         = require('gulp-plumber'),
    sourcemaps      = require('gulp-sourcemaps'),
    notify          = require('gulp-notify'),
    imagemin        = require('gulp-imagemin'),
    autoprefixer    = require('gulp-autoprefixer');

// serve
gulp.task('serve',['css'],function(){
    browserSync.init({
        proxy: "http://qhfa.mac.com/",
        baseDir: "./",
        port: 8017,
        notify:false,
        browser: "google chrome"
    });
    gulp.watch('public/static/mobile/scss/*.scss',['css']);
    gulp.watch(['app/index/view/**/*.html','app/mobile/view/**/*.html']).on('change',reload);
})

// css
gulp.task('css',function(){
    gulp.src(['public/static/mobile/scss/*.scss'])
    .pipe(sourcemaps.init())
    .pipe(concat('layout.scss'))
    .pipe(plumber())    
    .pipe(sass())
    .pipe(autoprefixer({
        browsers: ['last 2 versions','Firefox >= 20','iOS 8'],
        cascade: false
    }))
    .pipe(sourcemaps.write('.'))
    .pipe(gulp.dest('public/static/mobile/css'))
    .pipe(reload({stream: true}));    
})


// sass
// gulp.task('sass', function() {
//     return gulp.src("static/src/scss/*.scss")
//         .pipe(concat("main.min.scss"))
//         .pipe(plumber())
//         .pipe(sass())
//         .pipe(autoprefixer({
//             browsers: ['last 2 versions','Firefox >= 20','iOS 8'],
//             cascade: false
//         }))
//         // .pipe(minify())
//         .pipe(gulp.dest("static/build/css"))
//         .pipe(reload({stream: true}));
// });


// js
// gulp.task('js',function(){
//     gulp.src('src/js/*.js')
//     .pipe(plumber())
//     .pipe(sourcemaps.init())
//     .pipe(babel({  
//         presets: ['es2015']  
//       }))
//     // .pipe(babel())
//     .pipe(sourcemaps.write('.'))
//     .pipe(gulp.dest('build/js/'))
//     .pipe(reload({stream: true}));
// })

// default
gulp.task('default',['serve']);